<?php

namespace app\impl;

use app\interfaces\Task;
use app\common\business\UserCenter;
use app\common\business\WechatPush;


class SendWxPush implements Task
{
    public function run(array $data, string $taskId): ?bool
    {
        try {
            //获取配置
            $config = config("dictionary.wx_push");

            foreach ($data['patientIds'] as $val) {
                //获取患者票据
                $ticket = (new UserCenter())->generateTicket(["patient_code" => $val]);

                $type = $data['type'];
                $patient_id = $data['patient_id'];
                $locDesc = $data['deptName'];
                $admDate = $data['pushtime'];
                $note = '院后随访跟踪';
                $url = $config['jump_url'].$config['jump_address'][$type].'?ticket='.$ticket;
                (new WechatPush())->pushMessage($type, $patient_id, $locDesc, $admDate, $note, $url);
            }
            return true;
        } catch (\Exception $exception) {
            \think\facade\Log::record("微信推送异常:" . $exception->getMessage(), "error");
        }
        return true;
    }
}